export default function ({ $axios, redirect, store, app}) {
  $axios.onRequest(config => {
    // console.log('cookie1:::::::',config.headers)
    // console.log('cookie2:::::::'+$axios.defaults.headers.cookie)
    console.log('Making request to ' + config.url)
  })

  $axios.onResponse(res => {
    // console.log('code::::::::',res.data.code)
    if (res.data.code === 'ECP_USER_NO_LOGIN' ) {
      store.commit('LOGOUT_STATE')
      redirect('/login')
    }
    if (res.data.code === 'ECP_USER_ANEW_LOGIN') {
      store.commit('LOGOUT_STATE')
      redirect('/login')
    }
  })

  $axios.onError(error => {
    const code = parseInt(error.response && error.response.status)
    if (code === 400) {
      redirect('/400')
    }
    if (error.code === 500) {
      redirect('/error')
    }
  })
}
